package com.kfy.observerdemo.Observer;

/**
 * @ProjectName: ObserverDemo
 * @Package: com.kfy.observerdemo
 * @Author: K.F.Y
 * @Date: 2021/5/8
 */
public class PersonObserver implements Observer{

    private String name = "用户名称";

    public PersonObserver(String name){
        this.name = name;
    }

    @Override
    public void subscribe(Subject subject) {
        subject.attach(this);
    }

    @Override
    public void unsubscribe(Subject subject) {
        subject.detach(this);
    }

    @Override
    public void update(Subject subject) {
        System.out.println(this.name + " 订阅了"+subject.getName()+",它的内容为: " + subject.getContent());
    }
}
